package com.library.controller.admin;

import com.library.pojo.PageResult;
import com.library.pojo.Result;
import com.library.service.LendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.LocalDateTime;

@RestController("adminLend")
@RequestMapping("/admin/lend")
public class LendController {
    @Autowired
    private LendService lendService;

    /**
     * 管理端分页查询
     * @param page
     * @param pageSize
     * @param bookName
     * @param begin
     * @param end
     * @return
     */
    @GetMapping("/page")
    public Result pageQuery(@RequestParam(defaultValue = "1") Integer page
            , @RequestParam(defaultValue = "10") Integer pageSize, String bookName,
                            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end,Integer status) {
        PageResult result = lendService.pageQuery(page,pageSize,bookName,begin,end,status);
        return Result.success(result);
    }
    /**
     * 修改图书是否已归还
     */
    @PostMapping("/status/{status}")
    public Result isStatus(@PathVariable Integer status,Long id){
        lendService.isStatus(status,id);
        return Result.success();
    }
}
